//
//  ZJIntroduceView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/7/20.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJIntroduceView.h"

@interface ZJIntroduceView ()
/** titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;
/** 内容 */
@property (nonatomic, strong) UILabel *contentLabel;
/** 分割线 */
@property (nonatomic, strong) UILabel *underLine;
@end

@implementation ZJIntroduceView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.contentLabel];
        [self addSubview:self.underLine];
        
        self.titleLabel.text = title;
        
        self.titleLabel.sd_layout
        .topSpaceToView(self, 0)
        .leftSpaceToView(self, 12 * [UIScreen zj_screenWScale])
        .widthIs(self.width - 24 * [UIScreen zj_screenWScale])
        .heightIs(35 * [UIScreen zj_screenHScale]);
        
        self.contentLabel.sd_layout
        .topSpaceToView(self.titleLabel, 0 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.titleLabel)
        .widthRatioToView(self.titleLabel, 1)
        .heightIs(10);
        
        self.underLine.sd_layout
        .bottomSpaceToView(self, 0)
        .leftSpaceToView(self, 0)
        .widthIs(self.width)
        .heightIs(1);
        
    }
    return self;
}




#pragma mark - Setter
- (void)setContentText:(NSString *)contentText{
    _contentText = contentText;
    self.contentLabel.text = contentText;
    self.contentLabel.sd_layout
    .topSpaceToView(self.titleLabel, 0 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.titleLabel)
    .widthRatioToView(self.titleLabel, 1)
    .heightIs([self.contentLabel getLableSizeWithMaxWidth:self.contentLabel.width].height);
    [self.contentLabel updateLayout];
    
    self.height = self.contentLabel.height + (35 + 0 + 13) * [UIScreen zj_screenHScale];
    
}

#pragma mark - Getters
- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor themeColor];
        _titleLabel.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
    }
    return _titleLabel;
}

- (UILabel *)contentLabel{
    if (_contentLabel == nil){
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(12 * [UIScreen zj_screenWScale], 16 * [UIScreen zj_screenHScale], self.width - 24 * [UIScreen zj_screenWScale], 10)];
        _contentLabel.numberOfLines = 0;
        _contentLabel.characterSpace = 1;
        _contentLabel.font = [UIFont titleTextFont];
        _contentLabel.textColor = [UIColor textGrayColor];
        _contentLabel.lineSpace = 10 * [UIScreen zj_screenHScale];
    }
    return _contentLabel;
}
- (UILabel *)underLine{
    if (_underLine == nil){
        _underLine = [UILabel new];
        _underLine.backgroundColor = [UIColor zj_colorWithHexString:@"c9c9c9"];
    }
    return _underLine;
}

@end
